export default {
    data() {
        return {
            count: '测试promise',
            img1: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201703%2F17%2F20170317105527_vSfcK.gif&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1624170742&t=eb581cce6f76e3bd3577ce0a516bfe8d',
            img2: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fphoto.tuchong.com%2F395318%2Ff%2F7515321.jpg&refer=http%3A%2F%2Fphoto.tuchong.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1624170798&t=78104490f4d9a85c889d98bdd74bc6fd'
        };
    },
    methods: {
        promise(src) { 
            // const src = this.img1
            // console.log(src);
            
            // console.log(img.width);
            return new Promise(
                (resolve, reject) => {
                    const img = document.createElement('img')
                    img.onload = () => {
                        resolve(img)
                    }
                    img.onerror = () => {
                        const err = new Error(`图片加载失败${src}`)
                        reject(err)
                    }
                    img.src=src

                }
            )
        }


    }
};


